<?php


namespace plugin\exportcenter\app\bootstrap;


use plugin\exportcenter\app\service\ExportManager;
use SplFileInfo;
use core\utils\FileUtil;
use Webman\Bootstrap;
use Workerman\Worker;

/**
 * 注册所有的导出类
 * Class ExportBoot
 * @package plugin\exportcenter\app\bootstrap
 */
class ExportBoot implements Bootstrap
{
    public static function start(?Worker $worker)
    {
        $_exportDir = base_path() . '/plugin/exportcenter/app/strategy';

        FileUtil::fileIterator([$_exportDir], function ($fileUrl, SplFileInfo $fileInfo) {
            $ext = $fileInfo->getExtension();
            if ($ext === 'php') {
                $class = str_replace('/', "\\", substr(substr($fileUrl, strlen(base_path())), 0, -4));
                $clazz = new $class;
                ExportManager::getInstance()->register($clazz->action, $clazz);
            }
        });
    }
}